<div class="card">
  <div class="card-header">留言</div>
  <div class="card-body">
    <% if(comments.length > 0){ %>
    <% comments.forEach(function (comment) { %>
    <div class="media text-muted pt-3">
      <a href="/user/<%= comment.author._id %>"><img class="mr-2 rounded" alt="<%= comment.author.name %>" src="/img/<%= comment.author.avatar %>" data-holder-rendered="true" style="width: 32px; height: 32px;"></a>
      <div class="media-body pb-3 mb-0 small lh-125">
        <div class="d-flex justify-content-between align-items-center w-100"><%= comment.created_at %> | <%= comment.score || 0 %> 分</div>
        <span class="d-block"><strong class="text-gray-dark"><%- comment.content %></strong></span>
        <form class="needs-validation replyform_<%= comment._id %>" novalidate method="post" method="post" action="/comments/<%= comment._id %>/reply" style="display: none">
          <input name="postId_<%= comment._id %>" value="<%= postId %>" hidden>
          <input name="typeId_<%= comment._id %>" value="<%= typeId %>" hidden>
          <input name="score_<%= comment._id %>" value="0" hidden>
          <div class="form-group">
            <textarea class="form-control" id="content_<%= comment._id %>" name="content_<%= comment._id %>" rows="3" required></textarea>
          </div>
          <div class="text-right">
            <button class="btn btn-primary" type="submit">回复</button>
          </div>
        </form>
        <% (comment.subComment || []).forEach(function (sub) { %>
        <div class="media mt-3">
          <a class="pr-3" href="/user/<%= sub.author._id %>">
            <img class="rounded" style="width: 32px;height: 32px;" src="/img/<%= sub.author.avatar %>" alt="<%= sub.author.name %>">
          </a>
          <div class="media-body">
            <h5 class="mt-0"><%= sub.created_at %></h5>
            <%- sub.content %>
          </div>
        </div>
        <% }) %>
      </div>
      <% if (user && comment.author._id && user._id.toString() === comment.author._id.toString()) { %>
      <div class="btn-group">
        <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          操作
        </button>
        <div class="dropdown-menu">
          <a class="dropdown-item reply" data-id="<%= comment._id %>" href="javascript:void(0)">回复</a>
          <a class="dropdown-item del" href="/comments/<%= comment._id %>/remove">删除</a>
        </div>
      </div>
      <% } %>
    </div>
    <% }) %>
    <% } else { %>
    <div class="">暂无评论</div>
    <% } %>
  </div>
</div>
<% if (user) { %>
  <form class="needs-validation mt-3" novalidate method="post" action="/comments">
    <input name="postId" value="<%= postId %>" hidden>
    <input name="typeId" value="<%= typeId %>" hidden>
    <input name="score" value="0" hidden>
    <div class="form-group">
      <textarea class="form-control" id="content" name="content" rows="3" required></textarea>
    </div>
    <button class="btn btn-lg btn-primary btn-block" type="submit">留言</button>
  </form>
<% } %>
<!-- <div class="ui grid">
  <div class="four wide column"></div>
  <div class="eight wide column">
    <div class="ui segment">
      <div class="ui minimal comments">
        <h3 class="ui dividing header">留言</h3>

        <% comments.forEach(function (comment) { %>
          <div class="comment">
            <span class="avatar">
              <img src="/img/<%= comment.author.avatar %>">
            </span>
            <div class="content">
              <a class="author" href="/user/<%= comment.author._id %>"><%= comment.author.name %></a>
              <div class="metadata">
                <span class="date"><%= comment.created_at %> | <%= comment.score || 0 %> 分</span>
              </div>
              <div class="text"><%- comment.content %></div>

              <% if (user && comment.author._id && user._id.toString() === comment.author._id.toString()) { %>
                <div class="actions">
                  <a class="reply" data-id="<%= comment._id %>" href="javascript:void(0)">回复</a>
                  <a class="del" href="/comments/<%= comment._id %>/remove">删除</a>
                </div>
              <% } %>
              <form class="ui reply form replyform replyform_<%= comment._id %>" method="post" action="/comments/<%= comment._id %>/reply" style="display: none">
                <input name="postId_<%= comment._id %>" value="<%= postId %>" hidden>
                <input name="typeId_<%= comment._id %>" value="<%= typeId %>" hidden>
                <input name="score_<%= comment._id %>" value="0" hidden>
                <div class="ui heart rating replyrating replyrating_<%= comment._id %>" data-rating="0" data-max-rating="5" data-id="<%= comment._id %>"></div>
                <div class="field">
                  <textarea name="content_<%= comment._id %>"></textarea>
                </div>
                <input type="submit" class="ui icon button" value="回复" />
              </form>
            </div>
            <% (comment.subComment || []).forEach(function (sub) { %>
            <div class="comments">
              <div class="comment">
                <a class="avatar">
                  <img src="/img/<%= sub.author.avatar %>">
                </a>
                <div class="content">
                  <a class="author" href="/user/<%= sub.author._id %>"><%= sub.author.name %></a>
                  <div class="metadata">
                    <span class="date"><%= sub.created_at %></span>
                  </div>
                  <div class="text"><%- sub.content %></div>
                </div>
              </div>
            </div>
            <% }) %>
          </div>
        <% }) %>

        <% if (user) { %>
          <form class="ui reply form" method="post" action="/comments">
            <input name="postId" value="<%= postId %>" hidden>
            <input name="typeId" value="<%= typeId %>" hidden>
            <input name="score" value="0" hidden>
            <div class="ui heart rating commentrating" data-rating="0" data-max-rating="5"></div>
            <div class="field">
              <textarea name="content"></textarea>
            </div>
            <input type="submit" class="ui icon button" value="留言" />
          </form>
        <% } %>

      </div>
    </div>
  </div>
</div> -->
